<!-- 积分审批 -->
<template>
  <el-main class="base_main_content">
    <div class="base_screen_header">
      <span></span>
      <el-form :inline="true" class="base_search_form" @submit.prevent>
        <el-form-item>
            <el-input
              v-model="name"
              @keyup[native].enter="searchName"
              @change="searchName"
              placeholder="会员名称"
              clearable
              :suffix-icon="Search"
            />
          </el-form-item>
          <el-form-item>
            <el-input
              v-model="login"
              @keyup[native].enter="searchLogin"
              @change="searchLogin"
              placeholder="会员账号"
              clearable
              :suffix-icon="Search"
            />
          </el-form-item>
      </el-form>
    </div>
    <StatusBar :data="statusList" default="all" />
    <div class="base_main_margin_top">
      <ExamineTable :type="config.type" :data="data" :total="total" @getData="getList" />
    </div>
  </el-main>
</template>

<script setup>
import StatusBar from "@com/StatusBar.vue";
import ExamineTable from '@com/examine/ExamineTable.vue'
import { ref, reactive } from "vue";
import { Search } from "@element-plus/icons-vue";
import useRoute from "@util/router";
import api from "@api/examine"

const config = {
  type: 'points'
}

const route = useRoute();
const data = ref([])
const total = ref(0)

route.watchRouter("pointsexamine", () => {
  getStatistics()
  getList()
});

const statusList = reactive([{
  label: '全部',
  value: 'all',
  total: 0
}, {
  label: '待审批',
  value: '1007002',
  total: 0
}, {
  label: '已通过',
  value: '1007004',
  total: 0
}, {
  label: '已驳回',
  value: '1007003',
  total: 0
}])

const login = ref(route.query().login || '')
const name = ref(route.query().name || '')

function searchName(val) {
  route.replaceQuery('name', val)
}

function searchLogin(val) {
  route.replaceQuery('login', val)
}

getList()
function getList() {
  let routeQuery = route.query()
  api.list(config.type, {
    memberName: routeQuery.name,
    flowStatus: routeQuery.status,
    memberLoginName: routeQuery.login,
    page: routeQuery.p,
    size: routeQuery.s
  }, val => {
    total.value = val.total
    data.value = val.list.map(e => {
      if (e.flowType === '1006007') {
        e.flowTypeVal = '调整积分余额'
      } else {
        e.flowTypeVal = '解冻储值余额'
      }
      if (e.changeMoney > 0) {
        e.changeVal = '增加'
      } else {
        e.changeVal = '减少'
      }
      // 1007001草稿 1007002待审批 1007003被驳回 1007004审批通过
      switch (e.flowStatus) {
        case "1007001":
          e.state = "草稿"
          break
        case "1007002":
          e.state = "待审批"
          break
        case "1007003":
          e.state = "已驳回"
          break
        case "1007004":
          e.state = "已通过"
          break
      }
      return e
    })
  })
}

getStatistics()

function getStatistics() {
  let routeQuery = route.query()
  api.pointsNum(routeQuery.name, routeQuery.login, val => {
    statusData(val)
  })
}

function statusData(val) {
  statusList.forEach((e, i) => { e.total = val[i] })
}
</script>